package sample;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
import java.net.URL;
import java.util.ResourceBundle;

public class YearChoiceController implements Initializable {

    public Button confirm;
    public Button cancel;
    public TextField tf_year;
    public TextField tf_station;
    public DialogPane dialogPane;
//    private MainController mainController;

    String stationText = "";
    String yearText = "";
//    Alert choiceAlert = new Alert(Alert.AlertType.CONFIRMATION);
    Stage choiceAlert =  new Stage();


    public void choice(MainController mainController){
//        mainContro ller = mainController;
        ButtonType buttonType = new ButtonType("cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
        ButtonType buttonType1 = new ButtonType("confirm", ButtonBar.ButtonData.YES);

//        choiceAlert.getButtonTypes().setAll(buttonType,buttonType1);
        choiceAlert.setResizable(false);
        choiceAlert.setScene(new Scene(dialogPane));
        choiceAlert.show();
        tf_station.textProperty().addListener((observable, oldValue, newValue) -> stationText = newValue);
        tf_year.textProperty().addListener((observable, oldValue, newValue) -> yearText = newValue);
        cancel.setOnAction(event -> choiceAlert.close());
        confirm.setOnAction(event -> {
            if("".equals(stationText) || "".equals(yearText)){
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setContentText("站点或者年份不能为空!");
                alert.show();
            }else {
                System.out.println(stationText + yearText);
                mainController.searchByStationAndYear(stationText, yearText);
            }
            choiceAlert.close();
        });

    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
    }
}
